﻿#region Usings
using System;
using System.Web.Mvc;
using System.Web.Routing;

using BK.Repositories.Abstract;
using BK.Repositories.EF;

using Ninject;
#endregion

namespace BK.Infrastructure
{
    public class NinjectControllerFactory : DefaultControllerFactory
    {
        #region Readonly & Static Fields
        private readonly IKernel _ninjectKernel;
        #endregion

        #region C'tors
        public NinjectControllerFactory()
        {
            _ninjectKernel = new StandardKernel();
            AddBindings();
        }
        #endregion

        #region Instance Methods
        protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
        {
            return controllerType == null 
                ? null 
                : (IController) _ninjectKernel.Get(controllerType);
        }

        private void AddBindings()
        {
            _ninjectKernel.Bind<ICurrenciesRepository>().To<CurrenciesRepository>();
            _ninjectKernel.Bind<IUsersRepository>().To<UsersRepository>();
            _ninjectKernel.Bind<IAccountsRepository>().To<AccountsRepository>();
        }
        #endregion
    }
}